package jastgen.util;

import static jastgen.util.Util.*;

public class T2<T0, T1> {

	public final T0 e0;
	public final T1 e1;

	public static <T0, T1> T2<T0, T1> tuple(
			final T0 e0,
			final T1 e1)
	{
		return new T2<T0, T1>(e0, e1);
	}

	public T2(
			final T0 e0,
			final T1 e1)
	{
		this.e0 = e0;
		this.e1 = e1;
	}

	@Override
	public boolean equals(
			final Object rhs)
	{
		if(this == rhs)
			return true;
		if(rhs instanceof T2<?, ?>)
			return equalsImpl((T2<T0, T1>)rhs);
		return false;
	}

	private boolean equalsImpl(
			final T2<T0, T1> rhs)
	{
		if(!eq(e0, rhs.e0))
			return false;
		if(!eq(e1, rhs.e1))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 17;
		hash += hash(e0);
		hash *= 31;
		hash += hash(e1);
		return hash;
	}
}
